package com.myhome.money.jetty.controller;

import com.myhome.money.jetty.pojo.TestUser;
import com.myhome.money.jetty.service.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 许路路
 */
@RestController
public class HomeController {

    private static Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private HelloService helloService;

    @GetMapping("index")
    public String index() {
        logger.debug("1234debug....");
        logger.info("1234info....");
        logger.warn("1234warn....");
        logger.error("1234error...");
        helloService.sayHi();
        return "hello world";
    }

    @GetMapping("test01")
    public String test01(TestUser user) {
        logger.debug("1234debug...." + user.getChild().getName());
        logger.info("1234info...." + user.getName());
        helloService.sayHi();
        return "hello world";
    }

    @GetMapping("test02")
    public String test02(TestUser user) {
        if (logger.isDebugEnabled()) {
            logger.debug("1234debug....{}.", user.getChild().getName());
        }
        logger.info("1234info....{}", user.getName());
        helloService.sayHi();
        return "hello world";
    }

    @GetMapping("test03")
    public String test02(int state) {

        try {
            helloService.hello(state);
        } catch (Exception ex) {
            logger.error("error:", ex);
            throw new IllegalStateException(ex.getMessage());
        }
        return "hello world";
    }

}
